/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.domain.Studentnote;
import me.zhengjie.modules.system.service.StudentnoteService;
import me.zhengjie.modules.system.domain.vo.StudentnoteQueryCriteria;
import lombok.RequiredArgsConstructor;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author shitou
* @date 2024-08-15
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "学生笔记表管理")
@RequestMapping("/api/studentnote")
public class StudentnoteController {

    private final StudentnoteService studentnoteService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
//    @PreAuthorize("@el.check('studentnote:list')")
    public void exportStudentnote(HttpServletResponse response, StudentnoteQueryCriteria criteria) throws IOException {
        studentnoteService.download(studentnoteService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询学生笔记表")
    @ApiOperation("查询学生笔记表")
//    @PreAuthorize("@el.check('studentnote:list')")
    public ResponseEntity<List<Studentnote>> queryStudentnote(StudentnoteQueryCriteria criteria){
        return new ResponseEntity<>(studentnoteService.queryAll(criteria),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增学生笔记表")
    @ApiOperation("新增学生笔记表")
//    @PreAuthorize("@el.check('studentnote:add')")
    public ResponseEntity<Object> createStudentnote(@Validated @RequestBody Studentnote resources){
        studentnoteService.create(resources);
        return new ResponseEntity<>(resources.getId(),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改学生笔记表")
    @ApiOperation("修改学生笔记表")
//    @PreAuthorize("@el.check('studentnote:edit')")
    public ResponseEntity<Object> updateStudentnote(@Validated @RequestBody Studentnote resources){
        studentnoteService.update(resources);
        return new ResponseEntity<>(resources.getId(),HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除学生笔记表")
    @ApiOperation("删除学生笔记表")
//    @PreAuthorize("@el.check('studentnote:del')")
    public ResponseEntity<Object> deleteStudentnote(@RequestBody List<Integer> ids) {
        studentnoteService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}